<?php get_instance()->view('common/header');?>
<style>
    .weui-check{left: 23px;    top: 19px;}
    .weui-cell__hd{position:relative;}
    .weui-cell__hd input[type=radio]{position:absolute;left:0;top:0;width:100%;height:100%;z-index:1;opacity:0;}
    .labelshit{width:1em;height:1em;display:block;}
    .labelshit img{width:100%;height:100%;}
</style>
<body>
<?php if (!empty($list)):?>
    <div class="list pb50">
        <?php  foreach ($list as $k => $v):?>
            <div class="weui-cells m0" >
                <div class="weui-cell weui-cell_access chooseAddress" addressid = '<?php echo $v['id']?>' over_distance=<?php echo $v['over_distance'] ?>>
                    <?php if($v['over_distance'] == 1):?>
                        <div class="weui-cell__bd weui-media-box_text">
                            <h4 class="weui-media-box__title f09">
                                <?php echo $v['consignee']?> <?php echo $v['gender'] == 1 ? '先生' : '女士'?>
                                <?php echo $v['_mobile']?>
                            </h4>
                            <p class="weui-media-box__desc f07 cor6"><?php echo $v['_address_str']?></p>
                            <p class="weui-media-box__desc f07 cor6"><?php echo $v['_address']?></p>
                        </div>
                    <?php endif;?>
                    <?php if($v['over_distance'] == 2):?>
                        <div class="weui-cell__bd weui-media-box_text">
                            <h4 class="weui-media-box__title f08 cor9">
                                <?php echo $v['consignee']?> <?php echo $v['gender'] == 1 ? '先生' : '女士'?>
                                <?php echo $v['_mobile']?>
                            </h4>
                            <p class="weui-media-box__desc f06 cor9"><?php echo $v['_address_str']?></p>
                            <p class="weui-media-box__desc f06 cor9"><?php echo $v['_address']?></p>
                        </div>
                        <img class="pos" style="width:3.75em;right:10%;" src="<?php echo $this->staticUrl?>img/chaochu.png">
                    <?php endif;?>
                </div>
                <div class="weui-cell weui-check__label" for="x<?php echo $k?>">
                    <div class="weui-cell__bd"></div>
                    <div class="weui-cell__ft">
                        <div class="vCenter">
                            <a href="<?php echo getUrl('user/editAddress?id='.$v['id'].'&latitude='.$lat.'&longitude='.$lng)?>" class="f08 cor9 mr10"><img class="heightimg di mbmin mr5" src="<?php echo $this->staticUrl?>img/png/pic108.png" alt="">编辑</a>
                            <a href="<?php echo getUrl('user/rmAddress?address_id='.$v['id'])?>"
                               class="f08 cor9 ajax-request-btn" alert-message="是否确认删除？">
                                <img class="heightimg di mbmin mr5" src="<?php echo $this->staticUrl?>img/png/pic109.png" alt="">
                                删除
                            </a>
                        </div>
                    </div>
                </div>
            </div>
        <?php endforeach;?>
    </div>
<?php else:?>
    <div class="statebox chuizhi jdjz" style="flex: 1;height: 100%;">
        <img class="stateimgda mb5" src="<?php echo $this->staticUrl?>img/png/pic38.png" alt="">
        <span class="f09 cor9 tc mb20">你还没有收货地址哦～添加一个吧！</span>
<!--        <a href="--><?php //echo getUrl('user/addAddress')?><!--" class="daborbtnPub mb10 f12">添加新地址</a>-->
    </div>
<?php endif;?>
<div class="posbtnbox">
    <a href="<?php echo getUrl('user/addAddress'.'?latitude='.$lat.'&longitude='.$lng)?>" class="kbtn"><span class="f14 lh10">+</span> 新增地址</a>
</div>
</body>
<script src="<?php echo $this->staticUrl?>js/base.js"></script>
<script type="text/javascript">
    $("input[type=radio]").click(function(){
        var id = $(this).val();
        blockUI.show('处理中...');
        var _this = $(this);
        var img31 = '<?php echo $this->staticUrl?>img/png/pic31.png';
        var img30 = '<?php echo $this->staticUrl?>img/png/pic30.png';
        $.ajax('<?php echo getUrl('user/setAddressDefault');?>', {
            dataType:'json',
            type:'post',
            data:{address_id:id},
            error:function(){
                blockUI.hide();
                show_message({status:0, message:'请求超时'});
            },
            timeout:60000,
            success:function(e,textStatus,jqXHR){
                blockUI.hide();
                show_message(e);
                if (e.status == 1) {
                    _this.parents(".weui-cells").siblings(".weui-cells").find(".labelshit>img").attr('src', img31);
                    _this.siblings(".labelshit").find("img").attr('src', img30);
                }
            }
        });
    });
</script>
<script>
    $('.chooseAddress').click(function () {
        var over_distance= $(this).attr("over_distance");
        if(over_distance == 2){
            layer.open({
                title: '超出配送范围'
                ,content: '该地址超出商家配送范围，请重新选择'
                ,btn: '确定'
            });
            return false;
        }
        var id = $(this).attr('addressid');
        var info = $(this).find('h4').text();
        var address = $(this).find('p:eq(1)').text();
        var parent = window.parent;
        var product = '<?php echo isset($_GET['product'])?$_GET['product']:0;?>';
        parent.$(".mask").fadeOut(300);
        parent.$(".PeisPicker").fadeOut(300);
        setTimeout(function(){
            parent.$(".shopcarbox").css("z-index","2");
        },500)
        parent.$('.userAddress').find('h1').text(info);
        parent.$('.userAddress').find('p').text(address);
        parent.address_id = id;
        //console.log(parent.param);
        parent.changeAddress();
    });
</script>
</html> 